export default {
    raw2Stu,getDateString
}

function processData(raw) {
    let route1 = {};//嘉定-宝山
    let route2 = {};//宝山-嘉定
    route1.type = 'booked';
    route2.type = 'booked';
    route1.date = raw.dataList[0].departureTime.substring(0, 10);
    route2.date = route1.date;
    route1.startingPoint = '嘉定校区北门';
    route1.terminus = '东区食堂北';
    route2.startingPoint = '东区食堂北';
    route2.terminus = '嘉定校区北门';
    route1.trips = [];
    route2.trips = [];
    raw.dataList.forEach(function (v) {
        if (v.pathId === 7&&v.remainTickets!==0) {
            route1.trips.push({
                departureTime: v.departureTime.substring(11),
                remainTickets: v.remainTickets
            })
        }
        if (v.pathId === 8&&v.remainTickets!==0) {
            route2.trips.push({
                departureTime: v.departureTime.substring(11),
                remainTickets: v.remainTickets
            })

        }
    });
    return [route1, route2];
}

function raw2Stu(raw){
    let x={
        type:'预约校车',
        start:'',
        end:'',
        time:raw.departureTime,
        price:0,
        remainTickets:raw.remainTickets===null?'可预约':raw.remainTickets,
        info:{}
    };


    if(raw.pathId===7){
        x.start='嘉定'
        x.end='宝山'
    }
    if(raw.pathId===8){
        x.start='宝山'
        x.end='嘉定'
    }
    if(raw.pathId===19){
        x.start='延长'
        x.end='宝山'
    }
    if(raw.pathId===20){
        x.start='宝山'
        x.end='延长'
    }
    if(raw.pathId===29){
        x.start='延长'
        x.end='嘉定'
    }
    if(raw.pathId===30){
        x.start='嘉定'
        x.end='延长'
    }
    let info={};
    info.busId=raw.busId;
    info.bookDeadLine=raw.bookDeadLine;
    info.saleDeadLine=raw.saleDeadLine;
    info.pathBegin=raw.pathBegin;
    info.pathEnd=raw.pathEnd;
    info.bookTime=raw.bookTime;
    info.saleTime=raw.saleTime;
    info.seats=raw.seats;
    return x;
}
function getDateString(date) {
    let year = date.getFullYear().toString();
    let month = (date.getMonth() + 1).toString().padStart(2, '0');
    let day = date.getDate().toString().padStart(2, '0');
    return year + '-' + month + '-' + day;
}